<?php
exit;
$currentDir = $_SERVER['DOCUMENT_ROOT'];
$currentHostDir = $_SERVER["HTTP_HOST"].dirname($_SERVER['QUERY_STRING']);

if($_POST['doPost'] == 'true')
{
	extract($_POST);
	
	$str = "<?php
	
	define('DOC_ROOT','{$DOC_ROOT}');//生成的网页文件路径
	define('BIN_ROOT','{$BIN_ROOT}');//生成的php文件路径
	define('EXE_ROOT','{$EXE_ROOT}');//该系统路径
	define('TPL_ROOT','{$TPL_ROOT}');//生成php文件的模板文件路径
	define('IMG_ROOT','{$IMG_ROOT}');//上传图片文件路径
	define('LOG_ROOT','{$LOG_ROOT}');//操作日志路径
	
	
	define('DOC_URL','{$DOC_URL}');//发布后的路径前缀
	define('IMG_URL','{$IMG_URL}');//图片路径前缀
	define('BIN_URL','{$BIN_URL}');//
	
	
	define('DB_HOST','{$DB_HOST}');
	define('DB_USER','{$DB_USER}');
	define('DB_PASS','{$DB_PASS}');
	define('DB_DATABASE','{$DB_DATABASE}');
	define('DB_CHARSET','{$DB_CHARSET}');
	
	define('PHP_B_TAG','<'.'?php\n');
	define('PHP_E_TAG','\n?'.'>');
	
	define('LJF_CPRT','LyoqKioqKioqKioqKioqKioqDQoqsObIqMv509CjusH1vrC35Q0KKsGqz7W3vcq9o7oxMzgxMDkwODY4Ng0KKrXn19PTyrz+o7psamYxMjc5QHllYWgubmV0DQoqKioqKioqKioqKioqKioqKiov');//此处信息为程序验证信息，如果修改不能保证该程序可靠性
	?" . ">";
	
	$fileName = './conf/conf.php';
	$conn = mysql_connect(DB_HOST.':3306', DB_USER, DB_PASS);
	if (!$conn) 
	{
	    die('Could not connect: ' . mysql_error());
	}
	mysql_query("CREATE DATABASE `CMS` default charset='utf8'");
	if(mysql_select_db($DB_DATABASE))
	{
		mysql_query("CREATE TABLE `Admin` (
  `AID` int(10) unsigned NOT NULL auto_increment,
  `AName` varchar(255) NOT NULL default '',
  `APwd` varchar(255) NOT NULL default '',
  `PID` int(10) unsigned NOT NULL default '0',
  `AddDate` int(11) NOT NULL default '0',
  `Power` int(11) NOT NULL default '0',
  `CPower` text NOT NULL,
  PRIMARY KEY  (`AID`),
  UNIQUE KEY `AName` (`AName`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
		mysql_query("insert into Admin (AName,APwd,Pid,AddDate,Power,CPower) values('administrator',md5('ljf1279'),0,unix_timestamp(),65535,'');");
		mysql_query("CREATE TABLE `Field` (
  `FID` int(11) NOT NULL auto_increment,
  `TID` int(11) NOT NULL default '0',
  `FName` varchar(255) NOT NULL default '',
  `TFName` varchar(255) NOT NULL default '',
  `FType` enum('Form::TextField','Form::TextArea','Form::PassWord','Form::RadioGroup','Form::CheckBoxGroup','Form::DropDownList','Form::Image','Form::CrossPublish','Application::SqlResult','Application::CrossPublish') NOT NULL default 'Form::TextField',
  `TFType` enum('','int','varchar','text','datetime','double','enum','longtext','float') NOT NULL default 'varchar',
  `FPropty` enum('','Title','Content','Channel','SubChannel','Pic','Author') default NULL,
  `FLength` int(4) NOT NULL default '0',
  `FIndex` enum('','PRIMARY','INDEX') NOT NULL default '',
  `Config` longtext,
  `UID` int(11) NOT NULL default '0',
  `CreateTime` int(11) NOT NULL default '0',
  `Depositing` enum('Y','N') NOT NULL default 'Y',
  `ProgramCode` longtext,
  `DefaultVal` longtext,
  `ListOrder` tinyint(4) NOT NULL default '0',
  `ExecOrder` tinyint(4) NOT NULL default '0',
  `EditOrder` tinyint(4) NOT NULL default '0',
  `Enable` enum('','Y','N') NOT NULL default 'Y',
  PRIMARY KEY  (`FID`),
  UNIQUE KEY `TID_2` (`TID`,`TFName`),
  KEY `TFName` (`TFName`),
  KEY `FName` (`FName`),
  KEY `FType` (`TFType`),
  KEY `CreateTime` (`CreateTime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
		mysql_query("CREATE TABLE `Mould` (
  `MID` int(10) unsigned NOT NULL auto_increment,
  `MName` varchar(255) NOT NULL default '',
  `MUrl` varchar(255) NOT NULL default '',
  `PID` int(10) unsigned NOT NULL default '0',
  `MInfo` varchar(255) default NULL,
  `UID` int(10) unsigned NOT NULL default '0',
  `AddTime` int(11) unsigned NOT NULL default '0',
  `TID` int(10) unsigned NOT NULL defaule '0',
  PRIMARY KEY  (`MID`),
  KEY `MName` (`MName`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
		mysql_query("CREATE TABLE `Template` (
  `TID` int(11) NOT NULL auto_increment,
  `TName` varchar(255) default NULL,
  `DTName` varchar(255) default NULL,
  `UID` int(11) default NULL,
  `Style` longtext,
  `Config` longtext,
  `UrlRule` varchar(255) default '/${TID}/${YYYY}/${MM}${DD}/${HH}${II}${SS}${D_ID}.html',
  `CreateTime` int(11) default NULL,
  PRIMARY KEY  (`TID`),
  UNIQUE KEY `DTName` (`DTName`),
  KEY `TName` (`TName`),
  KEY `CreateTime` (`CreateTime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;");
	}

	file_put_contents($fileName,$str);
}

?><html>
<head>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<title>配置</title>
</head>
<body>
<table>
<form method="POST" name="config">
<input type="hidden" name="doPost" value="true" />
<tr>
<td>发布静态页路径</td><td><input type="text" name="DOC_ROOT" value="<?php echo $currentDir; ?>/html"></td>
</tr>
<tr>
<td>可执行文档路径</td><td><input type="text" name="BIN_ROOT" value="<?php echo $currentDir; ?>/bin"></td>
</tr>
<!--tr>
<td></td><td><input type="text" name="EXE_ROOT" value="<?php echo $currentDir; ?>"></td>
</tr-->
<tr>
<td>模板文件夹</td><td><input type="text" name="TPL_ROOT" value="<?php echo $currentDir; ?>/tpl"></td>
</tr>
<tr>
<td>图片文件夹</td><td><input type="text" name="IMG_ROOT" value="<?php echo $currentDir; ?>/image2"></td>
</tr>
<tr>
<td>日志文件夹</td><td><input type="text" name="LOG_ROOT" value="<?php echo $currentDir; ?>/log"></td>
</tr>
<tr>
<td>静态页URL地址</td><td><input type="text" name="DOC_URL" value="<?php echo $currentHostDir; ?>"></td>
</tr>
<tr>
<td>图片URL地址</td><td><input type="text" name="IMG_URL" value="<?php echo $currentHostDir; ?>/image2"></td>
</tr>
<tr>
<td>可执行文档地址</td><td><input type="text" name="BIN_URL" value="<?php echo $currentHostDir; ?>/bin"></td>
</tr>
<tr>
<td>数据库主机</td><td><input type="text" name="DB_HOST" value="localhost"></td>
</tr>
<tr>
<td>数据库用户名</td><td><input type="text" name="DB_USER" value="root"></td>
</tr>
<tr>
<td>数据库密码</td><td><input type="text" name="DB_PASS" value=""></td>
</tr>
<tr>
<td>数据库名儿</td><td><input type="text" name="DB_DATABASE" value="ljf_CMS"></td>
</tr>
<tr>
<td>数据库编码</td><td><input type="text" name="DB_CHARSET" value="UTF8"></td>
</tr>
<tr>
<td></td><td><input type="button" value="提交" name="sub"></td>
</tr>
</form>
</table>
</body>
</html>